package com.ocom.webapi.controller;

import com.ocom.common.constant.CompanyServiceUrl;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.company.MngAccountInfoRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.common.utils.StringUtil;
import com.ocom.security.authentication.YoCiUser;
import com.ocom.security.utils.SecurityUtils;
import com.ocom.webapi.feign.CompanyClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class MngAccountInfoController {

  @Autowired
  private CompanyClientService companyClientService;

  @PostMapping(CompanyServiceUrl.URL_account)
  public Result selectAccountsByPhone(@RequestBody MngAccountInfoRequest request) {
    Result list = companyClientService.selectAccountsByPhone(request);
    return ResultUtil.success(list.getData());
  }

  @PostMapping(CompanyServiceUrl.URL_addMngAccount)
  public Result addMngAccount(@RequestBody MngAccountInfoRequest mngAccountInfoRequest) {
    if (StringUtil.isEmpty(mngAccountInfoRequest.getPhone()) || !StringUtil.isPhone(
        mngAccountInfoRequest.getPhone())) {
      return ResultUtil.error(ResultEnum.Err_4705);
    }
    Result result = companyClientService.addMngAccount(mngAccountInfoRequest);
    return ResultUtil.success(result.getData());
  }

}
